home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: new-news.sprintlink.net!eskimo!news
- From: mag@eskimo.com (mAg)
- Subject: Re: A quick newbie question...hopefully...HELP!
- X-Nntp-Posting-Host: tia1.eskimo.com
- Message-ID: <Dpw2qA.M2n@eskimo.com>
- Sender: news@eskimo.com (News User Id)
- Organization: *.*
- X-Newsreader: WinVN 0.93.10
- References: <4kn8gk$6t1@info.evansville.net>
- Date: Mon, 15 Apr 1996 05:46:57 GMT
-
- In article <4kn8gk$6t1@info.evansville.net> (Sat, 13 Apr 1996 03:58:36 GMT),
- gilligan@evansville.net says :
- >
- >Hi!
- > I am just starting at C, and have a question...one of my problems is I
- >have to create a type of "Word Processor" where, regardless of number
- >of carriage returns or spaces, I have to cram as many words as
- >possible onto one line, be it 65 spaces or 40 (whatever the number),
- >but there must be one space in between each word, and the line cannot
- >end in the middle of the word. The user is done when he/she hits
- >CONTROL-Z, and then everything that he/she has typed is reformatted to
- >as many lines as needed. So, in other words, in this program, one
- >could type:
- >***********************************************************************************
- ******
- >THE DOG WENT
- >TO THE VET'S PLACE AND THEN REALIZED THAT
- >HE
- >WAS GETTING
- >A SHOT IN THE BUTT.
- >*****************************************************************************
- >And then when they hit Control-Z, it should read like this:
- >THE DOG WENT TO THE VET'S PLACE AND THEN REALIZED THAT HE WAS GETTING
- >A SHOT IN THE BUTT.
- >So you see how it is like a word processor, kind of. Now, my thoughts
- >were either to use GETCHAR, or just get a string at a time, but I am a
- >bit confused on this latter part...any ideas would be GREATLY
- >appreciated...due to the fact that I don't get back here much, please
- >send all questions/comments/suggestions to:
- >gilligan@evansville.net
- >
- >And MANY thanks in return!!
- >Gilligan
- >
- >
-
- I would say, a good way to do it is :
-
- read in all the text as one string using fgets(stdin,...) and use sscanf() to break
- it into words and append a space to every word.
-
-
- --
- /* --------------------------------------------------------
- MAG@ESKIMO.COM
- http://www.eskimo.com/~mag/index.html
- ***********************************************************
- To understand recursion one must first understand recursion
- ***********************************************************
- -------------------------------------------------------- */
-
-